<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>测试this的作用</title>
</head>
<body>
<p>
    编号：
    <input type="button" onclick="generate(this)" value="生成" />
</p>
<script>
    function generate(obj){
        var num = Math.random()*100+1;
        obj.value = num;
    }
    var firstName = "test";
    var person={
        id:110,
        firstName:"tom",
        lastName:"jobs",
        fullName:function(){
            //this在对象的方法中，代表当前person对象
            return this.firstName+" "+this.lastName;
        }
    };
    console.log(person.fullName());
    function test(){
        console.log(this);//window对象
    }
    test();
    alert(this);
</script>
</body>
</html>